package com.rimi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.rimi.bean.UserBean;
import com.rimi.service.UserService;
import com.rimi.service.impl.MenuServiceImpl;
import com.rimi.service.impl.UserServiceImpl;

@Controller
@SessionAttributes({"ub","ps"})

public class LoginController {

	@Autowired
	private UserService us;
	
	@Autowired
	private MenuServiceImpl ms;

	@RequestMapping("login")
	public String login(UserBean ub, Model m) {
		System.out.println("dfgdfgdf");
		ub = us.login(ub);
		if (ub != null) {
			// spring解析器自动添加前缀和后缀
			m.addAttribute("ub", ub);
			m.addAttribute("ps", ub.getUserPassword());
			// 用户对应的菜单
			m.addAttribute("menus", ms.getMenuByRoleId(ub.getRb().getRoleId()));
			// 默认为转发,重定向为"redirect:index"
			return "index";
		} else {
			return "login";
		}
	}
	
	
	@RequestMapping("getLogin2")
	public  String getLogin2(Model m) {
		return  "login";
	}
	
	@RequestMapping("getLogin")
	public  String getLogin(Model m) {
		return  "login";
	}

	
}
